package com.lincoln.framework.interfaces;

import java.util.Vector;

/**
 * 协议结构接口
 *
 * @author lincoln
 */
public abstract class BaseProtocol extends Vector<Byte> {
    /**
     * 该协议的指令
     *
     * @return
     */
    public abstract byte[] getCmd();

    /**
     * 生成serverCmd的key
     * @return
     */
    public String getCmdText(){
        String res = "";
        for(byte b: getCmd()){
            res += Integer.toHexString(b);
        }
        return res;
    }

    /**
     * 检查这个包是否合法
     *
     * @return
     */
    public abstract boolean verify();

    /**
     * 因为最终是以byte发出,所以需要有转换成byte
     *
     * @return
     */
    public byte[] toBytes() {
        byte[] res = new byte[size()];
        int i = 0;
        for (Byte b : this) {
            res[i++] = b;
        }
        return res;
    }

    @Override
    public String toString() {
        return "抽象类的toString";
    }
}
